<?php

namespace App\Http\Controllers\App\Ppe;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Ppe as Model;
use App\Http\Requests;

class PpeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $models = Model::whereCompanyId(\Auth::user()->company_id)
            ->orderByRaw('Concat(sort,\',\',id) asc')
            ->paginate(10);
        return view('ppe.ppe.index',[
            'models'=>$models
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $models = new Model();
        return view('depart.create',[
            'models'=>$models,
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Requests\DepartRequest $request)
    {
        $data = $request->input();
        $data['company_id'] = \Auth::user()->company_id;

        Model::create($data);
        return redirect()->route('depart.create');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $depart = Model::find($id);
        return view('depart.show',[
            'depart'=>$depart
        ]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
//        $depart = Depart::find($id);
//        return view('depart.form',[
//            'depart'=>$depart
//        ]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Requests\DepartRequest $request, $id)
    {
//        $depart = Depart::find($id);
//        $depart->fill($request->input());
//        $depart->save();
//        return redirect()->route('depart.edit',['id'=>$id]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Model::destroy($id);
        return redirect()->route('depart.index');
    }
}
